package com.aistar.service.impl;

import com.aistar.mapper.DynamicPraiseMapper;
import com.aistar.pojo.DynamicPraise;
import com.aistar.pojo.DynamicPraiseExample;
import com.aistar.service.DynamicPraiseService;
import com.aistar.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DynamicPraiseServiceImpl implements DynamicPraiseService {
    private final DynamicPraiseMapper dynamicPraiseMapper;

    @Autowired
    public DynamicPraiseServiceImpl(DynamicPraiseMapper dynamicPraiseMapper) {
        this.dynamicPraiseMapper = dynamicPraiseMapper;
    }

    @Override
    public ServerResponse getByCidAndPid(Integer customerId, Integer dynamicId) {
        DynamicPraiseExample example = new DynamicPraiseExample();
        example.createCriteria()
                .andCustomerIdEqualTo(customerId)
                .andDynamicIdEqualTo(dynamicId);
        List<DynamicPraise> dynamicPraiseList = dynamicPraiseMapper.selectByExample(example);
        if (dynamicPraiseList != null && dynamicPraiseList.size() > 0)
            return ServerResponse.getSuccess(dynamicPraiseList.get(0));
        return ServerResponse.getFailed();
    }


}
